package com.REPDPMSystem.Controller;
import com.REPDPMSystem.Service.EmployeeService;
import com.REPDPMSystem.Service.ProjectService;
import com.REPDPMSystem.Utils.R;
import com.REPDPMSystem.Entity.Employee;
import com.REPDPMSystem.Entity.Project;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//获取网盘文件信息，项目信息，
@RestController
@CrossOrigin
public class ProjectController {
    @Autowired
    ProjectService projectService;
    @Autowired
    EmployeeService employeeService;

    //要staff_id,通过它来识别权限和所经手的项目
    //员工有下载、上传，删除！自己！生成的文件、查看操作
    //主管和老板拥有网盘的所有权限
    //报价只对老板和主管可见
    //前台功能，但是老板要有吗？
    @CrossOrigin
    @PostMapping("/POST/CreateProjectInfo")
    public R createProjectInfo(@RequestBody Project project){
        return projectService.createProject(project)?R.ok():R.error().message("创建项目信息失败！");
    }

    @CrossOrigin
    @PostMapping("/POST/ChangeProjectInfo")
    public R changeProjectInfo(@RequestBody Project project){
        return projectService.changeProject(project)? R.ok():R.error().message("更新项目信息失败！");
    }
    @CrossOrigin
    @PostMapping("/POST/ProjectAllocation")
    public R projectAllocation(@RequestParam(value = "project")String projectstr,@RequestParam(value = "employee") String employeestr){
        Project  project = JSON.parseObject(projectstr,Project.class);
        Employee employee = JSON.parseObject(employeestr,Employee.class);
        return projectService.projectAllocation(project,employee)? R.ok():R.error().message("分配项目失败！");
    }
    //看到自己的项目清单
    @CrossOrigin
    @PostMapping("/GET/ProjectInfo")
    public R getProjectInfo(@RequestParam(value = "employee") String employeestr){
        Employee employee = JSON.parseObject(employeestr,Employee.class);
        System.out.println(employee.getEmployee_name());
        System.out.println(12345);
        switch(employeeService.getEmployeePositionById(employee.getStaff_id())){
            case Boss :return R.ok().data("ProjectInfo",new JSONArray(projectService.getProjectInfoBoss()));
            case Model_Supervisor :
            case Rendering_Supervisor :
            case Post_production_Supervisor : return R.ok().data("ProjectInfo",new JSONArray(projectService.getProjectInfoSupervisor()));
            case Model_Employee :
            case Rendering_Employee :
            case Post_production_Employee : return R.ok().data("ProjectInfo",new JSONArray(projectService.getProjectInfoEmployee(employee)));
            case Apprentice : return R.ok().data("ProjectInfo",new JSONArray(projectService.getProjectInfoApprentice()));
        }
        return R.error().message("获取项目信息失败");
    }
}

